#!/bin/bash
#set -e
###############################################################################
# Author	:	Erik Dubois
# Website	:	https://www.erikdubois.be
# Website	:	https://www.arcolinux.info
# Website	:	https://www.arcolinux.com
# Website	:	https://www.arcolinuxd.com
# Website	:	https://www.arcolinuxb.com
# Website	:	https://www.arcolinuxiso.com
# Website	:	https://www.arcolinuxforum.com
###############################################################################
#
#   DO NOT JUST RUN THIS. EXAMINE AND JUDGE. RUN AT YOUR OWN RISK.
#
###############################################################################

result=$(systemd-detect-virt)

#if installed on vmware
if [ $result = "vmware" ];
	then
		#activate vmware
		if pacman -Qi open-vm-tools &> /dev/null; then
			systemctl enable vmtoolsd.service
			systemctl start vmtoolsd.service
		fi
		#remove virtualbox
		if [ -f /etc/xdg/autostart/vboxclient.desktop ]; then
			rm /etc/xdg/autostart/vboxclient.desktop
		fi

		if pacman -Qi virtualbox-guest-utils &> /dev/null; then
			pacman -Rns virtualbox-guest-utils --noconfirm
		fi
fi

if [ $result = "oracle" ];
	then
		#remove vmware
		if [ -f /etc/xdg/autostart/vmware-user.desktop ]; then
   		rm /etc/xdg/autostart/vmware-user.desktop
		fi

		if pacman -Qi open-vm-tools &> /dev/null; then
			pacman -Rns open-vm-tools --noconfirm
		fi
fi

if [ $result = "none" ];
	then
		#remove virtualbox
		if [ -f /etc/xdg/autostart/vboxclient.desktop ]; then
   		rm /etc/xdg/autostart/vboxclient.desktop
		fi

		if pacman -Qi virtualbox-guest-utils &> /dev/null; then
			pacman -Rns virtualbox-guest-utils --noconfirm
		fi
		#remove vmware
		if [ -f /etc/xdg/autostart/vmware-user.desktop ]; then
   		rm /etc/xdg/autostart/vmware-user.desktop
		fi

		if pacman -Qi open-vm-tools &> /dev/null; then
			pacman -Rns open-vm-tools --noconfirm
		fi

	  systemctl disable virtual-machine-check.service
fi
